package com.blog.wl2023.config;

import com.blog.wl2023.listener.RestResponseInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author wule
 * @data 2023年08月15日18时
 * @description  添加路径拦截器
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

	/**
	 * SpringMVC 需要手动添加拦截器
	 * @param registry
	 */
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		RestResponseInterceptor respInterceptor = new RestResponseInterceptor();
		registry.addInterceptor(respInterceptor);
		WebMvcConfigurer.super.addInterceptors(registry);
	}

	/**
	 * 创建RestTemplate的Bean
	 * @return Bean
	 */
	@Bean
	public RestTemplate restTemplate() {
		return new RestTemplate();
	}

}
